import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
} from '@nestjs/common';
import { TransferService } from './transfer.service';
import { completeUploadDto, preUploadDto } from './transfer.dto';

@Controller('transfer')
export class TransferController {
  constructor(private readonly transferService: TransferService) {}

  //文件预上传
  @Post('/preUpload')
  async preUpload(@Req() req, @Body() body: preUploadDto) {
    const userId = req.user.user_id as number;
    return this.transferService.preUpload(userId, body.filename, body.filetype);
  }

  //文件上传成功
  @Post('/completeUpload')
  async completeUpload(@Req() req, @Body() body: completeUploadDto) {
    const userId = req.user.user_id as number;
    return await this.transferService.completeUpload(body, userId);
  }

  //获取查看链接
  @Get('/view/:id')
  async viewFile(@Param('id') id: string) {
    return await this.transferService.viewFile(id);
  }
}
